import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.media.opengl.GL;
import javax.swing.JOptionPane;

import com.sun.opengl.util.texture.Texture;
import com.sun.opengl.util.texture.TextureIO;



public class GameState
{

	public MainCanvas gameCanvas;
//	public SoundManager m_SoundManager = new SoundManager();
	
	public GameState (MainCanvas gameCanvas)
	{
		this.gameCanvas = gameCanvas;
	}
	
	public void InitVar() {}
	
	public void LoadResources() {}
	
	public void Update() {}
	
	public void Display(GL gl) {}
	
	public void KeyPressed(KeyEvent e) {}
	
	public void KeyReleased(KeyEvent e) {}
	///////////////////////////////////////////////////////////////
	// Support methods 
	///////////////////////////////////////////////////////////////
	
	public Texture LoadTexture(String filepath)
	{
		Texture texture;
	    BufferedImage image;
	    
		try 
		{
			image = ImageIO.read(this.getClass().getResource(filepath));
			texture = TextureIO.newTexture(image, false);
		} 
		catch (IllegalArgumentException e)
		{
			JOptionPane.showMessageDialog(null, "Can not load file \"" + filepath + "\". The application will be exit !", "Error", JOptionPane.ERROR_MESSAGE);
			System.exit(0);
			return null;
		}
		catch (IOException e)
		{
			e.printStackTrace();
			return null;
		}

		return texture;
	}

	public void TurnOffDepth(GL gl)
	{
		gl.glDisable(GL.GL_DEPTH_TEST); 
	}
	
	public void TurnOnDepth(GL gl)
	{
		gl.glEnable(GL.GL_DEPTH_TEST); 
	    gl.glDepthFunc(GL.GL_LEQUAL); 
	}

	public void SaveGame()
	{
//		try {
//			IO.WriteFile(gameCanvas.SaveGame, GameDefine.fileName_SaveGame);
//		} catch (IOException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
	}
	
	public void LoadGame()
	{
//		try {
//			IO.ReadFile(gameCanvas.SaveGame, GameDefine.fileName_SaveGame, 30); 
//		} 
//		catch (IOException e) {
//			/*for (int i = 0; i < 30; i++)
//				gameCanvas.SaveGame.add(null);*/
//		} 
//		catch (ClassNotFoundException e) {
//		}
	}
}
